package com.emm.yixun.customer.service.impl;
import java.util.ArrayList;
import java.util.List;

import javax.jws.WebService;

import com.emm.yixun.common.model.dto.*;
import com.emm.yixun.common.model.enums.DelFlagEnum;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.emm.yixun.basic.service.CallCustomerService;
import com.emm.yixun.basic.service.CustomerService;
import com.emm.yixun.basic.service.DataPermissionService;
import com.emm.yixun.basic.service.DialTransactionalService;
import com.emm.yixun.basic.service.ProjectService;
import com.emm.yixun.basic.service.TelRecordService;
import com.emm.yixun.basic.service.UserService;
import com.emm.yixun.common.app.ChannelToM2ReqDto;
import com.emm.yixun.common.app.ChannelToM2ResDto;
import com.emm.yixun.common.app.servletentity.ChannelToM2Res;
import com.emm.yixun.common.constant.SysConstants;
import com.emm.yixun.common.exception.ResponseCode;
import com.emm.yixun.common.model.CallCustomer;
import com.emm.yixun.common.model.CallCustomerInfo;
import com.emm.yixun.common.model.Customer;
import com.emm.yixun.common.model.Project;
import com.emm.yixun.common.model.TelRecord;
import com.emm.yixun.common.model.User;
import com.emm.yixun.common.model.enums.SourceEnum;
import com.emm.yixun.common.page.Page;
import com.emm.yixun.common.response.Response;
import com.emm.yixun.common.response.ResponseList;
import com.emm.yixun.common.utils.MobileUtil;
import com.emm.yixun.customer.service.CallCustomerServiceFacade;

@Service("callCustomerServiceFacade")
@WebService(name="com.emm.yixun.customer.service.CallCustomerServiceFacade")
public class CallCustomerServiceFacadeImpl implements CallCustomerServiceFacade{
	private  final Logger   logger = LoggerFactory.getLogger(this.getClass()); 
	
	@Autowired
	private CallCustomerService service;
	@Autowired
	private UserService userService;
	@Autowired
	private TelRecordService telRecordService;
	@Autowired
	private CustomerService customerService;
	@Autowired
	private DialTransactionalService dialTransactionalService;
	
	@Autowired
	private DataPermissionService dataPermissionService;
	@Autowired
	private ProjectService projectService;

	@Override
	public Response<CallCustomerDto> save(CallCustomerDto dto) {
		Response<CallCustomerDto> response=new Response<CallCustomerDto>();
		try {
			if(null==dto){
				response.fail(ResponseCode.PARAM_INVALID.getCode(), ResponseCode.PARAM_INVALID.formatMessage("保存"));
				return response;
			}
			CallCustomerDto mDto=service.create(dto);
			if(null==mDto){
				response.fail("80000", "保存数据错误");
				return response;
			}
			response.success(mDto);
		} catch (Exception e) {
			response.fail(ResponseCode.SYSTEM_EXCEPTION.getCode(), ResponseCode.SYSTEM_EXCEPTION.getMessageTemplate());
			logger.error("保存数据错误：{}",e);
		}
		return response;
	}

	@Override
	public Response<Integer> updateByPrimaryKey(CallCustomerDto dto,Boolean selective) {
		Response<Integer> response=new Response<Integer>();
		try {
			if(null==selective || null==dto || null==dto.getId()){
				response.fail(ResponseCode.PARAM_INVALID.getCode(), ResponseCode.PARAM_INVALID.formatMessage("更新"));
				return response;
			}
			
			if(selective){
				int count=service.update(dto);
				if(count>0){
					response.success(Integer.valueOf(count));
				}else{
					response.fail("90001", "更新数据失败");
				}
			}else{
				response.fail("90000", "暂未实现,修改参数selective=true即可");
			}
		} catch (Exception e) {
			response.fail(ResponseCode.SYSTEM_EXCEPTION.getCode(), ResponseCode.SYSTEM_EXCEPTION.getMessageTemplate());
			logger.error("更新数据错误：{}",e);
		}
		return response;
	}

	@Override
	public Response<Integer> deleteByPrimaryKey(Long id) {
		Response<Integer> response=new Response<Integer>();
		try {
			if(null==id){
				response.fail(ResponseCode.PARAM_INVALID.getCode(), ResponseCode.PARAM_INVALID.formatMessage("删除"));
				return response;
			}
			CallCustomerDto mDto=new CallCustomerDto();
			mDto.setId(id);
			int count=service.destroy(mDto);
			if(count>0){
				response.success(Integer.valueOf(count));
			}else{
				response.fail("90001", "删除数据失败");
			}
		} catch (Exception e) {
			response.fail(ResponseCode.SYSTEM_EXCEPTION.getCode(), ResponseCode.SYSTEM_EXCEPTION.getMessageTemplate());
			logger.error("删除数据错误：{}",e);
		}
		return response;
	}
	
    @Override
	public Response<CallCustomerInfo> findById(Long id) {
		Response<CallCustomerInfo> response=new Response<CallCustomerInfo>();
		try {
			if(null==id){
				response.fail(ResponseCode.PARAM_INVALID.getCode(), ResponseCode.PARAM_INVALID.formatMessage("主键查询"));
				return response;
			}
			CallCustomer entity=service.selectById(id);
			if(null==entity){
				response.fail("90001", "主键查询数据失败");
			}else{
				CallCustomerInfo info = new CallCustomerInfo();
				BeanUtils.copyProperties(entity, info);
				info.setYhPhone(MobileUtil.getPhone(entity.getPhone()));
				response.success(info);
			}
		} catch (Exception e) {
			response.fail(ResponseCode.SYSTEM_EXCEPTION.getCode(), ResponseCode.SYSTEM_EXCEPTION.getMessageTemplate());
			logger.error("主键查询数据错误：{}",e);
		}
		return response;
	}

	@Override
	public ResponseList<CallCustomerInfo> findByDto(CallCustomerDto dto) {
		ResponseList<CallCustomerInfo> response=new ResponseList<CallCustomerInfo>();
		try {
			if(null==dto){
				response.fail(ResponseCode.PARAM_INVALID.getCode(), ResponseCode.PARAM_INVALID.formatMessage("查询"));
				return response;
			}
			List<CallCustomer> list=service.selectListByDto(dto);
			if(null==list){
				response.fail(ResponseCode.NO_DATA_FOUND.getCode(), ResponseCode.NO_DATA_FOUND.formatMessage("查询"));
				return response;
			}
			List<CallCustomerInfo> listInfo = new ArrayList<CallCustomerInfo>();
            for(int i = 0; i < list.size(); i++){
            	CallCustomer call = (CallCustomer)list.get(i);
            	CallCustomerInfo info = new CallCustomerInfo();
            	BeanUtils.copyProperties(call, info);
            	if(call.getMaintainUser() != null){
            		User user = userService.selectById(call.getMaintainUser());
            		info.setMaintainUserName(user.getUserName());
            	}
            	listInfo.add(info);
            }
			response.success(listInfo);
		} catch (Exception e) {
			response.fail(ResponseCode.SYSTEM_EXCEPTION.getCode(), ResponseCode.SYSTEM_EXCEPTION.getMessageTemplate());
			logger.error("查询数据错误：{}",e);
		}
		return response;
	}

	@Override
	public Page<CallCustomerInfo> findPageByDto(CallCustomerDto dto, Integer begin,Integer row) {
		Page<CallCustomerInfo> response=new Page<CallCustomerInfo>();
		try {
			if(null==dto || null==begin || null==row){
				response.setSuccess(false);
				response.setErrorMsg("参数不合法");
				return response;
			}
			if (SysConstants.openDataPermission) {
				String dataPermission = dataPermissionService.dataPermissionCondition(dto.getPermissionUserId(),
						dto.getResourcesCode(), dto.getPrefix(), dto.getColumnName());
				String[] dataPermissionArr = dataPermission.split(":");
				if ("00".equals(dataPermissionArr[0])) {
					response.setErrorMsg("无call客模块数据查看权限，请联系管理员！");
					response.setSuccess(false);
					return response;
				}
				dto.setDataPermission(dataPermissionArr[1]);
			}
			Page<CallCustomer> page = service.getPageModel(dto, begin, row);
			if(null==page.getRows()){
				response.setSuccess(false);
				response.setErrorMsg("分页数据不存在");
				return response;
			}
			Page<CallCustomerInfo> pageInfo = new Page<CallCustomerInfo>();
			List<CallCustomerInfo> listInfo = new ArrayList<CallCustomerInfo>();
            List<CallCustomer> list = page.getRows();
            for(int i = 0; i < list.size(); i++){
            	CallCustomer call = (CallCustomer)list.get(i);
            	CallCustomerInfo info = new CallCustomerInfo();
            	BeanUtils.copyProperties(call, info);
            	if(call.getMaintainUser() != null){
            		User user = userService.selectById(call.getMaintainUser());
            		info.setMaintainUserName(user.getUserName());
            	}
            	listInfo.add(info);
            }
            pageInfo.setRows(listInfo);
            pageInfo.setPageNumber(page.getPageNumber());
            pageInfo.setPageSize(page.getPageSize());
            pageInfo.setTotal(page.getTotal());
            pageInfo.setTotalPages(page.getTotalPages());
            
			response=pageInfo;
			response.setSuccess(true);
		} catch (Exception e) {
			response.setSuccess(false);
			response.setErrorMsg(ResponseCode.SYSTEM_EXCEPTION.getMessageTemplate());
			logger.error("查询分页数据错误：{}",e);
		}
		return response;
	}
	
	@Override
	public ResponseList<CallCustomerInfo> setValueGetList(CallCustomerDto dto) {
		ResponseList<CallCustomerInfo> response=new ResponseList<CallCustomerInfo>();
		try {
			if(null==dto){
				response.fail(ResponseCode.PARAM_INVALID.getCode(), ResponseCode.PARAM_INVALID.formatMessage("查询"));
				return response;
			}
			List<CallCustomer> list=service.setValueGetList(dto);
			if(null==list){
				response.fail(ResponseCode.NO_DATA_FOUND.getCode(), ResponseCode.NO_DATA_FOUND.formatMessage("查询"));
				return response;
			}
			List<CallCustomerInfo> listInfo = new ArrayList<CallCustomerInfo>();
            for(int i = 0; i < list.size(); i++){
            	CallCustomer call = (CallCustomer)list.get(i);
            	CallCustomerInfo info = new CallCustomerInfo();
            	BeanUtils.copyProperties(call, info);
            	if(call.getMaintainUser() != null){
            		User user = userService.selectById(call.getMaintainUser());
            		info.setMaintainUserName(user.getUserName());
            	}
            	listInfo.add(info);
            }
			response.success(listInfo);
		} catch (Exception e) {
			response.fail(ResponseCode.SYSTEM_EXCEPTION.getCode(), ResponseCode.SYSTEM_EXCEPTION.getMessageTemplate());
			logger.error("查询数据错误：{}",e);
		}
		return response;
	}
	
	@Override
	public ResponseList<CallCustomer> setValueGetListDto(CallCustomerDto dto) {
		ResponseList<CallCustomer> response=new ResponseList<CallCustomer>();
		try {
			if(null==dto){
				response.fail(ResponseCode.PARAM_INVALID.getCode(), ResponseCode.PARAM_INVALID.formatMessage("查询"));
				return response;
			}
			List<CallCustomer> list = service.setValueGetList(dto);
		
			response.success(list);
		} catch (Exception e) {
			response.fail(ResponseCode.SYSTEM_EXCEPTION.getCode(), ResponseCode.SYSTEM_EXCEPTION.getMessageTemplate());
			logger.error("查询数据错误：{}",e);
		}
		return response;
	}
	
	@Override
	public ResponseList<CallCustomer> distinctPhone(CallCustomerDto dto) {
		ResponseList<CallCustomer> response=new ResponseList<CallCustomer>();
		try {
			if(null==dto){
				response.fail(ResponseCode.PARAM_INVALID.getCode(), ResponseCode.PARAM_INVALID.formatMessage("查询"));
				return response;
			}
			List<CallCustomer> list = service.distinctPhone(dto);
			response.success(list);
		} catch (Exception e) {
			response.fail(ResponseCode.SYSTEM_EXCEPTION.getCode(), ResponseCode.SYSTEM_EXCEPTION.getMessageTemplate());
			logger.error("查询数据错误：{}",e);
		}
		return response;
	}
	

	@Override
	public Response<Integer> getCount(CallCustomerDto dto) {
		Response<Integer> response=new Response<Integer>();
		try {
			if(null==dto){
				response.fail(ResponseCode.PARAM_INVALID.getCode(), ResponseCode.PARAM_INVALID.formatMessage("查询"));
				return response;
			}
			if (SysConstants.openDataPermission) {
				String dataPermission = dataPermissionService.dataPermissionCondition(dto.getPermissionUserId(),
						dto.getResourcesCode(), dto.getPrefix(), dto.getColumnName());
				String[] dataPermissionArr = dataPermission.split(":");
				if ("00".equals(dataPermissionArr[0])) {
					response.setEntity(0);
					response.setSuccess(true);
					return response;
				}
				dto.setDataPermission(dataPermissionArr[1]);
			}
			int i = service.getCount(dto);
			response.success(i);
		} catch (Exception e) {
			response.fail(ResponseCode.SYSTEM_EXCEPTION.getCode(), ResponseCode.SYSTEM_EXCEPTION.getMessageTemplate());
			logger.error("查询数据错误：{}",e);
		}
		return response;
	}
	
	@Override
	public ResponseList<TelRecordDto> getTelRecordList(TelRecordDto dto) {
		ResponseList<TelRecordDto> response=new ResponseList<TelRecordDto>();
		try {
			if(null==dto){
				response.fail(ResponseCode.PARAM_INVALID.getCode(), ResponseCode.PARAM_INVALID.formatMessage("查询"));
				return response;
			}
			List<TelRecord> list=telRecordService.selectListByDto(dto);
			if(null==list){
				response.fail(ResponseCode.NO_DATA_FOUND.getCode(), ResponseCode.NO_DATA_FOUND.formatMessage("查询"));
				return response;
			}
			List<TelRecordDto> listDto = new ArrayList<TelRecordDto>();
			for(int i = 0; i < list.size(); i++){
				TelRecord tel = (TelRecord)list.get(i);
				TelRecordDto info = new TelRecordDto();
            	BeanUtils.copyProperties(tel, info);
            	if(tel.getCreateUserId() != null){
            		User user = userService.selectById(tel.getCreateUserId());
            		info.setUserName(user.getUserName());
            	}
            	listDto.add(info);
            }
			response.success(listDto);
		} catch (Exception e) {
			response.fail(ResponseCode.SYSTEM_EXCEPTION.getCode(), ResponseCode.SYSTEM_EXCEPTION.getMessageTemplate());
			logger.error("查询数据错误：{}",e);
		}
		return response;
	}

	@Override
	public Response<TelRecordDto> callPhone(TelRecordDto dto) {
		Response<TelRecordDto> response=new Response<TelRecordDto>();
		try {
			if(null==dto){
				response.fail(ResponseCode.PARAM_INVALID.getCode(), ResponseCode.PARAM_INVALID.formatMessage("保存"));
				return response;
			}
			TelRecordDto tel = dialTransactionalService.call(dto);
			if(null==tel){
				response.fail("80000", "保存数据错误");
				return response;
			}
			response.success(tel);
		} catch (Exception e) {
			response.fail(ResponseCode.SYSTEM_EXCEPTION.getCode(), ResponseCode.SYSTEM_EXCEPTION.getMessageTemplate());
			logger.error("保存数据错误：{}",e);
		}
		return response;
	}
	
	@Override
	public Page<CallCustomerInfo> getWeifenpeiPageModel(CallCustomerDto dto, Integer begin,Integer row) {
		Page<CallCustomerInfo> response=new Page<CallCustomerInfo>();
		try {
			if(null==dto || null==begin || null==row){
				response.setSuccess(false);
				response.setErrorMsg("参数不合法");
				return response;
			}
			//查询去掉数据权限,同步的客户无法绑定user
//			if (SysConstants.openDataPermission) {
//				String dataPermission = dataPermissionService.dataPermissionCondition(dto.getPermissionUserId(),
//						dto.getResourcesCode(), dto.getPrefix(), dto.getColumnName());
//				String[] dataPermissionArr = dataPermission.split(":");
//				if ("00".equals(dataPermissionArr[0])) {
//					response.setErrorMsg("无call客模块数据查看权限，请联系管理员！");
//					response.setSuccess(false);
//					return response;
//				}
//				dto.setDataPermission(dataPermissionArr[1]);
//			}
			response = service.getWeifenpeiPageModel(dto, begin, row);
			if(null==response.getRows()){
				response.setSuccess(false);
				response.setErrorMsg("分页数据不存在");
				return response;
			}
            
			response.setSuccess(true);
		} catch (Exception e) {
			response.setSuccess(false);
			response.setErrorMsg(ResponseCode.SYSTEM_EXCEPTION.getMessageTemplate());
			logger.error("查询分页数据错误：{}",e);
		}
		return response;
	}
	
	@Override
	public Page<CallCustomerInfo> callFindPageByDto(CallCustomerDto dto, Integer begin,Integer row, List<com.emm.yixun.common.model.Resources> getPermitBtn) {
		Page<CallCustomerInfo> response=new Page<CallCustomerInfo>();
		try {
			if(null==dto || null==begin || null==row){
				response.setSuccess(false);
				response.setErrorMsg("参数不合法");
				return response;
			}
			if (SysConstants.openDataPermission) {
				String dataPermission = dataPermissionService.dataPermissionCondition(dto.getPermissionUserId(),
						dto.getResourcesCode(), dto.getPrefix(), dto.getColumnName());
				String[] dataPermissionArr = dataPermission.split(":");
				if ("00".equals(dataPermissionArr[0])) {
					response.setErrorMsg("无call客模块数据查看权限，请联系管理员！");
					response.setSuccess(false);
					return response;
				}
				dto.setDataPermission(dataPermissionArr[1]);
			}
			Page<CallCustomer> page = service.getCallPageModel(dto, begin, row);
			if(null==page.getRows()){
				response.setSuccess(false);
				response.setErrorMsg("分页数据不存在");
				return response;
			}
			Page<CallCustomerInfo> pageInfo = new Page<CallCustomerInfo>();
			List<CallCustomerInfo> listInfo = new ArrayList<CallCustomerInfo>();
            List<CallCustomer> list = page.getRows();
            for(int i = 0; i < list.size(); i++){
            	CallCustomer call = (CallCustomer)list.get(i);
            	CallCustomerInfo info = new CallCustomerInfo();
            	BeanUtils.copyProperties(call, info);
            	info.setYhPhone(MobileUtil.getPhone(call.getPhone()));
            	if(call.getMaintainUser() != null){
            		User user = userService.selectById(call.getMaintainUser());
            		info.setMaintainUserName(user.getUserName());
            	}
            	info.setPermitBtn(getPermitBtn);
            	listInfo.add(info);
            }
            pageInfo.setRows(listInfo);
            pageInfo.setPageNumber(page.getPageNumber());
            pageInfo.setPageSize(page.getPageSize());
            pageInfo.setTotal(page.getTotal());
            pageInfo.setTotalPages(page.getTotalPages());
            
			response=pageInfo;
			response.setSuccess(true);
		} catch (Exception e) {
			response.setSuccess(false);
			response.setErrorMsg(ResponseCode.SYSTEM_EXCEPTION.getMessageTemplate());
			logger.error("查询分页数据错误：{}",e);
		}
		return response;
	}
	
	@Override
	public ChannelToM2ResDto saveChannelToM2(ChannelToM2ReqDto dto) {
		ChannelToM2ResDto response = new ChannelToM2ResDto();
		List<ChannelToM2Res> failList = new ArrayList<ChannelToM2Res>();
		try {
			List<CallCustomer> list = dto.getCustomerList();
			if(list == null){
				response.setResult("0");
				response.setErrorCode("9999");
				response.setErrorMsg("List<CallCustomer>不能为null");
				return response;
			}
			
			//查询M2是否已有转入的客户
			List<String> phoneList = repeatPhone(list);
			//批量转入M2数据库
			for(int i = 0; i < list.size(); i++){
				CallCustomer call = (CallCustomer)list.get(i);
				CustomerDto entity = new CustomerDto();
				entity.setCustomerPhone(call.getPhone());
				ChannelToM2Res res = new ChannelToM2Res();
				res.setM2Id(Long.parseLong(call.getRecommendedChannelId())); //出错时，将渠道传入的ID返回
				if(StringUtils.isBlank(call.getUserName())){
					BeanUtils.copyProperties(call, res);
					res.setErrorMsg("客户姓名不能为空");
					failList.add(res);
					continue;
				}
				if(StringUtils.isBlank(call.getProjectCode())){
					BeanUtils.copyProperties(call, res);
					res.setErrorMsg("未找到绑定楼盘");
					failList.add(res);
					continue;
				}
				if(StringUtils.isBlank(call.getPhone())){
					BeanUtils.copyProperties(call, res);
					res.setErrorMsg("电话号码不能为空");
					failList.add(res);
					continue;
				}

				
				//过滤重复电话号码
    			boolean flag = true;
    			for(int p = 0; p < phoneList.size(); p++){
    				if(phoneList.get(p).indexOf(call.getPhone()) >= 0){
    					//当有重复时号码时，跳出循环
    					flag = false;
    					//保存错误信息
    					BeanUtils.copyProperties(call, res);
    					res.setErrorMsg("该手机号已存在，建议更换客户手机号再次报备后转客");
    					failList.add(res);
						//错误信息
						response.setFailList(failList);
						response.setResult("1");
						return response;
    				}
    			}
    			//当没有重复客户时，保存到数据库
    			if(flag){
    				//查询项目信息
    				ProjectDto proDto = new ProjectDto();
    				proDto.setProjectCode(call.getProjectCode());
    				Project pro = projectService.selectByDto(proDto);
    				if(pro == null){
    					//保存错误信息
    					BeanUtils.copyProperties(call, res);
    					res.setErrorMsg("未找到对应的楼盘");
    					failList.add(res);
    					continue;
    				}

    				UserDto userDto = new UserDto();
    				userDto.setMerchantId(pro.getMerchantId());
    				userDto.setIsAdmin("1");
    				List<User> userList = userService.selectListByDto(userDto);
					Long userId = 0L;
    				if(null != userList && userList.size() > 0){
						userId = userList.get(0).getId();
					}

    				CallCustomerDto callDto = new CallCustomerDto();
    				BeanUtils.copyProperties(call, callDto);
    				callDto.setProjectId(pro.getId());
    				callDto.setStatus("3"); //已转客
    				callDto.setImpId(0L); //渠道转客没有统计表ID，默认0
    				callDto.setMerchantId(pro.getMerchantId()); //商户ID
    				callDto.setCreateUserId(userId); //导入人ID
    				callDto.setCallNum("0"); //渠道转客没有沟通次数 ，默认0次
    				callDto.setDelFlag(DelFlagEnum.UNDEL.getNo());
    				callDto.setAssignedType("0"); //分配状态（0 待分配 1 已分配）
    				callDto.setSource(SourceEnum.CHANNEL.getNo());//数据来源
					callDto.setOrgStores(call.getAgentStoreName());//机构名称
        			service.create(callDto);
    			}
			}
			//转客总数
			int total = list.size();
			response.setTotal(total);
			//转客失败数
			int failNum = failList.size();
			response.setFailNum(failNum);
			//转客成功数
			int successNum = total - failNum;
			response.setSuccessNum(successNum);
			//错误信息
			response.setFailList(failList);
			response.setResult("1");
		} catch (Exception e) {
			logger.error("渠道转客失败：{}",e);
			response.setResult("0");
			response.setErrorCode("9999");
			response.setErrorMsg("渠道转客失败");
		}
		return response;
	}
	
	/**
	 * 查询电话号码是否有重复
	 * @param dtoList
	 * @return
	 */
    private List<String> repeatPhone(List<CallCustomer> dtoList){
    	List<String> phoneList = new ArrayList<String>();
    	String projectCode = "";
    	for(CallCustomer call : dtoList){
    		phoneList.add(call.getPhone());
    		if(StringUtils.isBlank(projectCode)){
				projectCode = call.getProjectCode();
			}
    	}

		//查询项目信息.判重根據項目來過濾
		ProjectDto proDto = new ProjectDto();
		proDto.setProjectCode(projectCode);
		Project pro = projectService.selectByDto(proDto);

    	CustomerDto dto = new CustomerDto();
    	dto.setPhoneList(phoneList);
    	dto.setProjectId(pro.getId());
    	List<Customer> res = customerService.selectCustomerPhoneByListPC(dto);
    	List<String> resList = new ArrayList<String>();
    	if(res != null){
    		for(int p = 0; p < res.size(); p++){
				Customer customer = (Customer)res.get(p);
				String phone = customer.getCustomerPhone() + "_" + customer.getPeMobile();
				resList.add(phone);
    		}
    	}
    	return resList;
    }
	
//	/**
//	 * 查询电话号码是否有重复
//	 * @param dtoList
//	 * @return
//	 */
//    private List<CallCustomer> repeatPhone(List<CallCustomer> dtoList){
//    	String sql = "";
//    	for(int i = 0; i < dtoList.size(); i++){
//    		CallCustomer dto = (CallCustomer)dtoList.get(i);
//    		sql += dto.getPhone() + "' or phone = '";
//    	}
//    	if(!"".equals(sql)){
//    		sql = " phone = '" + sql.substring(0, sql.length()-13);
//    	}
//    	CallCustomerDto dto = new CallCustomerDto();
//    	dto.setPhone(sql);
//    	logger.debug("查询电话号码是否重复的条件===="+sql);
//    	List<CallCustomer> res = service.distinctPhone(dto);
//    	if(res == null){
//    		res = new ArrayList<CallCustomer>();
//    	}
//    	return res;
//    }
}
